package com.design.marketPrj.application.controller;

import com.design.marketPrj.application.bean.PO.User;
import com.design.marketPrj.application.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.math.BigDecimal;

@Controller
public class BaseController {

    @Autowired
    UserService userService;

    public User getUser(){
        User principal = (User)SecurityUtils.getSubject().getPrincipal();
        User user = userService.getUserById(principal.getId());
        return user;
    }


    public String getUserName(){
        User user = (User)SecurityUtils.getSubject().getPrincipal();
        return getUser().getUsername();
    }

    public String getUserId(){
        User user = (User)SecurityUtils.getSubject().getPrincipal();
        return user.getId();
    }

    public BigDecimal getUserMoney(){
        return getUser().getMoney();
    }

    public boolean getAliBind(){
        return getUser().getAliBind();
    }


}
